package com.web.controller;

import com.dto.BaseDto;
import com.entity.Festival;
import com.page.PageInfo;
import com.web.service.FestivalService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/festivalController")
public class FestivalController {
    @Resource
    FestivalService festivalService;

    @RequestMapping("/festivals")
    @ResponseBody
   public BaseDto<Festival> getAll() throws Exception{
//        System.out.println("getAll");
//       List<Student> students = Arrays.asList(new Student[]{new Student("0901", "张三"), new Student("0902", "李四"), new Student("0901", "王二")});
//       return students;
        return festivalService.getAll();
   }

    @RequestMapping("/festivals/page")
    public ModelAndView getCustomersByPage(PageInfo pageInfo) throws Exception{
        BaseDto<Festival> dto = festivalService.getFestivalsByPage(pageInfo);

        return new ModelAndView("/back/festival/list", "dto", dto);
    }

    @RequestMapping("/festivals/page/json")
    @ResponseBody
    public BaseDto<Festival> getCustomersByPageJson(PageInfo pageInfo) throws Exception{
        return festivalService.getFestivalsByPage(pageInfo);
    }

    @PostMapping("/festival/post")
    @ResponseBody
    public ModelAndView add(Festival festival) throws Exception{
        BaseDto<Festival> dto =  festivalService.add(festival);
        return new ModelAndView("/back/festival/add", "dto", dto);
    }

    @PutMapping("/festival/put/{fid}")
    @ResponseBody
    public BaseDto<Festival> update(@PathVariable("fid") int fid) throws Exception{
        return  festivalService.update(fid);
    }

    @RequestMapping("/festival/{fid}/json")
    @ResponseBody
    public BaseDto<Festival> selectByPrimaryKeyWithActivitytype(@PathVariable("fid") int fid) throws Exception{
        return festivalService.selectByPrimaryKeyWithActivitytype(fid);
    }

}
